package com.wgz.flag.controller;

import com.wgz.flag.common.Result;

import com.wgz.flag.entity.PrivateMessage;
import com.wgz.flag.service.PrivateMessageService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/private/message")
@RequiredArgsConstructor
@CrossOrigin(origins = {"http://localhost:8081","http://localhost:8082"}, allowCredentials = "true")
public class PrivateMessageController {
    private final PrivateMessageService privateMessageService;

    @GetMapping("/history")
    public Result<List<PrivateMessage>> getHistoryMessages(
            @RequestParam Long userId,
            @RequestParam Long friendId) {
        return Result.success(privateMessageService.getHistoryMessages(userId, friendId));
    }

    @PostMapping("/read")
    public Result<Void> markAsRead(
            @RequestParam Long userId,
            @RequestParam Long friendId) {
        privateMessageService.markAsRead(userId, friendId);
        return Result.success();
    }
}